package co.com.going.filtros;


import co.com.going.modelo.Usuarioo;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * @author DILOVE
 */
public class FiltroAdministrador implements Filter{
    
    private FilterConfig configuration;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.configuration = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        Usuarioo usuarioo = (Usuarioo)((HttpServletRequest) request).getSession().getAttribute("usuario");
        if(usuarioo!=null){
            System.out.println("Usuario "+usuarioo.getNivelA());
            if(usuarioo.getNivelA().equals("2")){
                chain.doFilter(request, response);
            }else{                
                    ((HttpServletResponse) response).sendRedirect("../SesionInvalida.xhtml");
            }
        }else{
            ((HttpServletResponse) response).sendRedirect("../SesionInvalida.xhtml");
        }
    }

    @Override
    public void destroy() {
        this.configuration = null;
    }
    
}
